package com.acme.javaschool.sems.sem5memory;

import java.io.*;
import java.nio.Buffer;

public class LogParser {

    public static void main(String... args) {
        try {
            BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Java Student\\Desktop\\log.txt"));
            String s;
            String s0 = "";
            try {
                while (null != (s = in.readLine())) {
/*
                    try {
                        String gc = s.substring(s.indexOf("[GC"));
                        System.out.println(gc);
                    } catch (IndexOutOfBoundsException e) {
                        continue;
                    }
                    try {
                        String gc = s.substring(s.indexOf("[CMS"));
                        System.out.println(gc);
                    } catch (IndexOutOfBoundsException e) {
                        continue;
                    }
*/
//                    if (s.indexOf("[") != -1) {
                    if (s.length() > 6) {
//                        System.out.print(parseGCMessage(s));
                        System.out.print(s);
                        System.out.println("\t" + s0);
                    } else {
                        s0 = s;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    private static String parseGCMessage(String s) {
        String result = "";

        result += s.substring(0, s.indexOf(":")) + "\t";
        int yaEnd = s.indexOf("ParNew") + 8;
        result += s.substring(yaEnd, s.indexOf("K", yaEnd)) + "\t";



        return result;
    }

}
